package com.qiangesoft.rdp.starter.minio.core;

import com.qiangesoft.rdp.starter.minio.bucket.BucketAccessPolicyEnum;
import io.minio.StatObjectResponse;
import io.minio.messages.Bucket;
import org.springframework.web.multipart.MultipartFile;

import javax.servlet.http.HttpServletResponse;
import java.io.InputStream;
import java.util.List;

/**
 * minio文件服务
 *
 * @author qiangesoft
 * @date 2023-04-21
 */
public interface MinioTemplate {

    /**
     * 获取文件存储路径前缀
     *
     * @return
     */
    String getPath();

    /**
     * 创建桶
     *
     * @param bucketName
     * @throws Exception
     */
    void createBucket(String bucketName) throws Exception;

    /**
     * 创建桶
     *
     * @param bucketName
     * @param bucketPolicyEnum
     * @throws Exception
     */
    void createBucket(String bucketName, BucketAccessPolicyEnum bucketPolicyEnum) throws Exception;

    /**
     * 获取桶
     *
     * @return
     */
    List<Bucket> listBuckets() throws Exception;

    /**
     * 获取桶
     *
     * @param bucketName
     * @return
     * @throws Exception
     */
    Bucket getBucket(String bucketName) throws Exception;

    /**
     * 删除桶
     *
     * @param bucketName
     * @throws Exception
     */
    void removeBucket(String bucketName) throws Exception;

    /**
     * 上传文件
     *
     * @param bucketName
     * @param inputStream
     * @param fileName
     * @return
     * @throws Exception
     */
    String putObject(String bucketName, InputStream inputStream, String fileName) throws Exception;

    /**
     * 上传文件
     *
     * @param bucketName
     * @param file
     * @return
     * @throws Exception
     */
    String putObject(String bucketName, MultipartFile file) throws Exception;

    /**
     * 分享文件地址
     *
     * @param bucketName
     * @param objectName
     * @param expires
     * @return
     * @throws Exception
     */
    String getObjectURL(String bucketName, String objectName, Integer expires) throws Exception;

    /**
     * 获取文件
     *
     * @param bucketName
     * @param objectName
     * @return
     * @throws Exception
     */
    InputStream getObject(String bucketName, String objectName) throws Exception;

    /**
     * 获取文件
     *
     * @param bucketName
     * @param objectName
     * @return
     * @throws Exception
     */
    StatObjectResponse getObjectInfo(String bucketName, String objectName) throws Exception;

    /**
     * 下载文件
     *
     * @param bucketName
     * @param filename
     * @param response
     * @throws Exception
     */
    void download(String bucketName, String filename, HttpServletResponse response) throws Exception;

    /**
     * 删除文件
     *
     * @param bucketName
     * @param objectName
     * @throws Exception
     */
    void removeObject(String bucketName, String objectName) throws Exception;

    /**
     * 删除文件
     *
     * @param bucketName
     * @param objectNames
     * @throws Exception
     */
    void removeObjects(String bucketName, List<String> objectNames) throws Exception;
}
